<template>
  <div class="home-new">
    <HomePanel title="新鲜好物" sub-title="新鲜出炉 品质靠谱">
      <template #right><RbtMore path="/" /></template>
      <div ref="box" style="position: relative; height: 406px">
        <Transition name="fade">
          <!-- 面板内容 -->
          <ul v-if="goods.length" ref="pannel" class="goods-list">
            <li v-for="item in goods" :key="item.id">
              <router-link :to="`/product/${item.id}`">
                <img v-lazy="item.picture" alt="" />
                <p class="name ellipsis">{{ item.name }}</p>
                <p class="price">&yen;{{ item.price }}</p>
              </router-link>
            </li>
          </ul>
          <HomeSkeleton v-else bg="#f0f9f4" />
        </Transition>
      </div>
    </HomePanel>
  </div>
</template>

<script setup lang="ts">
import { findNew } from '@/api/home'
import { NewType } from '@/types/category'
// import { useIntersectionObserver } from '@vueuse/core'
import { useLazyData } from '@/utils'

const goods = ref<NewType[]>([])
const box = ref()
useLazyData(findNew, goods, box)
// const box = ref(null)
// const { result, target } = useLazyData(findNew)
// goods.value = result.value
// console.log(goods.value, 'sdsdsds')

// const { stop } = useIntersectionObserver(box, ([{ isIntersecting }]) => {
//   if (isIntersecting) {
//     stop()
//     findNew().then(res => {
//       goods.value = res.data.result
//     })
//   }
// })
</script>

<style scoped lang="scss">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    @include hoverShadow;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: $priceColor;
    }
  }
}
</style>
